﻿using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using SW.Lite.Infrastructure.Configuration;

namespace SW.Lite.Infrastructure.Helpers
{
    /// <summary>
    ///     配置文件辅助类
    /// </summary>
    public class ConfigHelper
    {
        private static ConfigHelper _instance;

        /// <summary>
        ///     Constructor
        /// </summary>
        public ConfigHelper()
        {
            var ht = ConfigurationManager.GetSection("StrongWorld") as Hashtable;
            if (ht == null) return;

            DebugMode = (bool)ht["DebugMode"];

            Connection = ht["Connection"] == null
                ? new Connection()
                : ht["Connection"] as Connection;

            Template = ht["Template"] == null
                ? new Template()
                : ht["Template"] as Template;

            Components = ht["Components"] == null
                ? new List<Component>()
                : ht["Components"] as List<Component>;

            Security = ht["Security"] == null
                ? new Security()
                : ht["Security"] as Security;

            Upload = ht["Upload"] == null
                ? new Upload()
                : ht["Upload"] as Upload;
        }

        /// <summary>
        ///     Gets the connection.
        /// </summary>
        public Connection Connection { get; private set; }

        /// <summary>
        ///     Gets the template.
        /// </summary>
        public Template Template { get; private set; }

        /// <summary>
        ///     IoC组件
        /// </summary>
        public List<Component> Components { get; set; }

        /// <summary>
        ///     安全配置
        /// </summary>
        public Security Security { get; set; }

        /// <summary>
        ///     上传配置
        /// </summary>
        public Upload Upload { get; set; }

        /// <summary>
        ///     Gets or sets a value indicating whether [debug mode].
        /// </summary>
        public bool DebugMode { get; set; }

        /// <summary>
        ///     Gets the instance.
        /// </summary>
        /// <value>The instance.</value>
        public static ConfigHelper Instance
        {
            get { return _instance ?? (_instance = new ConfigHelper()); }
        }
    }
}